Listing 3 shows how you can create a path using only off-curve control points. The path defined in this example contains four control points.
Listing 3 Creating a path using only off-curve control points
ComponentInstance vectorCodec;
Handle streamH;
Handle pathH;
gxPoint points[4];
Boolean isOnCurve[4];
int i;
/* open the vector codec component */
OpenADefaultComponent (decompressorComponentType,
kVectorCodecType, &vectorCodec);
/* create a new vector data stream */
CurveCreateVectorStream (vectorCodec, streamH);
/* specify the points for the path and whether each one is on it */
points[0].x = ff(50);
points[0].y = ff(50);
isOnCurve[0] = FALSE;
points[1].x = ff(150);
points[1].y = ff(50);
isOnCurve[1] = FALSE;
points[2].x = ff(150);
points[2].y = ff(150);
isOnCurve[2] = FALSE;
points[3].x = ff(50);
points[3].y = ff(150);
isOnCurve[3] = FALSE;
/* create the path and add the points to it */
CurveNewPath (vectorCodec, &pathH);
for (i = 0; i <= 3; i++)
CurveInsertPointIntoPath (vectorCodec, &points[i], pathH,
1, i, isOnCurve[i]);
/* add the path to the vector data stream */
CurveAddPathAtomToVectorStream (vectorCodec, pathH, streamH);
/* mark the end of the vector data stream by adding a
kCurveEndAtom atom to the stream */
CurveAddZeroAtomToVectorStream (vectorCodec, streamH);
/* use the vector codec here to decompress and display the vector data */
/* dispose of stream and path handles when done */
DisposeHandle (streamH);
DisposeHandle (pathH);
The four off-curve control points in this example form a square; the path that they define is a rounded square, as shown in Figure 59 .
Figure 59 A rounded path shape
Notice that the path is filled with the even-odd shape fill, which is the default for path shapes. You could, however, specify any shape fill for this path except the open-frame shape fill. The open-frame shape fill requires that the first and last points of the contour be on-curve points, and this path has no on-curve points.
| Previous | Chapter Contents | Chapter Top | Next |